package com.liu.qqRobot.event.controller;

import cn.hutool.json.JSONUtil;
import com.liu.qqRobot.event.entity.dto.EventReportingDTO;
import com.liu.qqRobot.event.service.EventService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/")
public class EventController {

    @Resource
    private EventService eventService;

    @PostMapping()
    public String eventReporting(@RequestBody Object o) {
        log.info("QQ事件上报原始信息：{}", JSONUtil.toJsonStr(o));
        EventReportingDTO eventReportingDTO = JSONUtil.toBean(JSONUtil.toJsonStr(o), EventReportingDTO.class);
//        log.info("QQ事件上报转Java信息：{}",JSONUtil.toJsonStr(eventReportingDTO));
//        if (eventReportingDTO.getGroupId() == 424907162L || eventReportingDTO.getSender().getGroupId() == 424907162L) {
            eventService.handleEvent(eventReportingDTO);
//        }
        return JSONUtil.toJsonStr(eventReportingDTO);
    }
}
